import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

let routes

// eslint-disable-next-line
if (screenWidth > 1200) {
  routes = [
    {
      path: '/',
      component: () => import('@/views/nav-pages/index.vue'),
      redirect: '/home',
      children: [
        {
          path: 'home',
          component: () => import('@/views/nav-pages/pages/home/index.vue'),
          meta: {
            title: '首页'
          }
        },
        {
          path: 'about',
          component: () => import('@/views/nav-pages/pages/about/index.vue'),
          meta: {
            title: '关于我们'
          },
          redirect: '/about/introduction',
          children: [
            {
              path: 'introduction',
              component: () =>
                import('@/views/nav-pages/pages/about/pages/introduction.vue')
            },
            {
              path: 'development',
              component: () =>
                import('@/views/nav-pages/pages/about/pages/development.vue')
            }
          ]
        },
        {
          path: 'news',
          component: () => import('@/views/nav-pages/pages/news/index.vue'),
          meta: {
            title: '新闻资讯'
          }
        },
        {
          path: 'school/:id?',
          component: () => import('@/views/nav-pages/pages/school/index.vue'),
          meta: {
            title: '我们的学校'
          }
        },
        {
          path: 'idea',
          component: () => import('@/views/nav-pages/pages/idea/index.vue'),
          meta: {
            title: '教育理念'
          }
        },
        {
          path: 'contact',
          component: () => import('@/views/nav-pages/pages/contact/index.vue'),
          meta: {
            title: '联系我们'
          }
        }
      ]
    },
    {
      path: '/news/:id',
      component: () => import('@/views/other-pages/new-detail.vue')
    }
  ]
} else {
  routes = [
    {
      path: '/',
      component: () => import('@/views/phone-pages/index.vue'),
      redirect: '/home',
      children: [
        {
          path: 'home',
          component: () => import('@/views/phone-pages/pages/home/index.vue'),
          meta: {
            title: '首页'
          }
        },
        {
          path: 'about',
          component: () => import('@/views/phone-pages/pages/about/index.vue'),
          meta: {
            title: '关于我们'
          },
          redirect: '/about/introduction',
          children: [
            {
              path: 'introduction',
              component: () =>
                import('@/views/phone-pages/pages/about/pages/introduction.vue')
            },
            {
              path: 'development',
              component: () =>
                import('@/views/phone-pages/pages/about/pages/development.vue')
            }
          ]
        },
        {
          path: 'news',
          component: () => import('@/views/phone-pages/pages/news/index.vue'),
          meta: {
            title: '新闻资讯'
          }
        },
        {
          path: 'school/:id?',
          component: () => import('@/views/phone-pages/pages/school/index.vue'),
          meta: {
            title: '我们的学校'
          }
        },
        {
          path: 'idea',
          component: () => import('@/views/phone-pages/pages/idea/index.vue'),
          meta: {
            title: '教育理念'
          }
        },
        {
          path: 'contact',
          component: () => import('@/views/phone-pages/pages/contact/index.vue'),
          meta: {
            title: '联系我们'
          }
        }
      ]
    },
    {
      path: '/news/:id',
      component: () => import('@/views/other-pages/new-detail-phone.vue')
    }
  ]
}

const router = new VueRouter({
  routes
})

router.beforeEach((to, _, next) => {
  to.meta.title && (document.title = to.meta.title)
  next()
})

export default router
